import React from 'react';
import { Routes, Route, Navigate } from 'react-router-dom';
import MainLayout from './layouts/MainLayout';
import Dashboard from './pages/Dashboard';
import DataArchive from './pages/DataArchive';
import BusinessMonitor from './pages/BusinessMonitor';
import DiskSpace from './pages/DiskSpace';
import DataManagement from './pages/DataManagement';
import DataSearch from './pages/DataSearch';
import PDSDataManager from './pages/PDSDataManager';
import PDSData from './pages/PDSData';
import AnomalyDetection from './pages/AnomalyDetection';
import ChineseEnglishCorrespondence from './pages/ChineseEnglishCorrespondence';
import UserManagement from './pages/UserManagement';
import DirectoryManagement from './pages/DirectoryManagement';
import DataStructureManager from './components/DataStructureManager';
import LogManagement from './pages/LogManagement';
import MyFavorites from './pages/MyFavorites';
import Login from './pages/Login';
import Register from './pages/Register';
import OrderDownload from './pages/OrderDownload';
import ReleaseHistory from './pages/ReleaseHistory';
import ReleaseDetail from './pages/ReleaseDetail';
import GIS from './pages/GIS';
import GISManagement from './pages/GISManagement';
import GISDetail from './pages/GISDetail';
import PermissionGuard from './components/PermissionGuard';
import AuthGuard from './components/AuthGuard';
import { AUTH_STORAGE_KEYS } from './config/authConfig';
import './App.css';

const App: React.FC = () => {
  return (
    <AuthGuard>
      <Routes>
      {/* 登录和注册页面 */}
      <Route path="/login" element={<Login />} />
      <Route path="/register" element={<Register />} />

      {/* 主应用路由 */}
      <Route path="/" element={<MainLayout />}>
        {/* 首页 */}
        <Route index element={<Dashboard />} />
        <Route path="home" element={<Dashboard />} />

        {/* 数据管理 */}
        <Route path="data-management" element={
          <PermissionGuard>
            <DataManagement />
          </PermissionGuard>
        } />
        <Route path="anomaly-detection" element={
          <PermissionGuard>
            <AnomalyDetection />
          </PermissionGuard>
        } />
        <Route path="release-history" element={
          <PermissionGuard>
            <ReleaseHistory />
          </PermissionGuard>
        } />
        <Route path="release-detail/:id" element={
          <PermissionGuard>
            <ReleaseDetail />
          </PermissionGuard>
        } />

        {/* 数据检索 */}
        <Route path="data-search" element={
          <PermissionGuard>
            <DataSearch />
          </PermissionGuard>
        } />
        <Route path="pds-service" element={
          <PermissionGuard>
            <PDSDataManager />
          </PermissionGuard>
        } />
        <Route path="pds-data" element={
          <PermissionGuard>
            <PDSData />
          </PermissionGuard>
        } />

        {/* 订单管理 */}
        <Route path="download-order" element={
          <PermissionGuard>
            <OrderDownload />
          </PermissionGuard>
        } />
        <Route path="my-favorites" element={
          <PermissionGuard>
            <MyFavorites />
          </PermissionGuard>
        } />

        {/* 信息统计 */}
        <Route path="info-statistics" element={
          <PermissionGuard>
            <BusinessMonitor />
          </PermissionGuard>
        } />
        <Route path="type-config" element={
          <PermissionGuard>
            <DataStructureManager />
          </PermissionGuard>
        } />
        <Route path="zh-en-config" element={
          <PermissionGuard>
            <ChineseEnglishCorrespondence />
          </PermissionGuard>
        } />
        <Route path="disk-path-config" element={
          <PermissionGuard>
            <DiskSpace />
          </PermissionGuard>
        } />

        {/* 运行管理 */}
        <Route path="dir-management" element={
          <PermissionGuard>
            <DirectoryManagement />
          </PermissionGuard>
        } />
        <Route path="user-management" element={
          <PermissionGuard>
            <UserManagement />
          </PermissionGuard>
        } />
        <Route path="log-management" element={
          <PermissionGuard>
            <LogManagement />
          </PermissionGuard>
        } />

        {/* 3D地球演示 */}
        <Route path="gis" element={<GIS />} />
        <Route path="gis-management" element={<GISManagement />} />
        <Route path="gis-detail" element={<GISDetail />} />
      </Route>
    </Routes>
    </AuthGuard>
  );
};

export default App;
